var express = require('express')
var path = require('path')
var cors = require('cors')

var usersRouter = require('./routes/users')
var loginRouter = require('./routes/login')

var app = express()

// 注册cors 处理跨域
app.use(cors())
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(express.static(path.join(__dirname, 'public')))
app.use(express.static(path.join(__dirname, './apidoc')))

var params = require('./middleware/params.js')
app.all('/*', params)
app.use('/', usersRouter)
app.use('/', loginRouter)

app.listen(8888, ['10.41.155.21', 'localhost'], () => {
  console.log('本地服务: http://localhost:8888')
  console.log('局域网服务: http://10.41.155.21:8888')
})